/*
 *  (C) Copyright 2008 Insula Tecnologia da Informacao Ltda.
 * 
 *  This file is part of Vulcano.
 *
 *  Vulcano is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Vulcano is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Vulcano.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.openinsula.vulcano.flex.example.persistence;

import java.util.ArrayList;
import java.util.Date;

import org.springframework.util.Assert;

public class EntityFactory {

	public static Department createDepartment(final String name) {
		Assert.hasText(name);

		Department department = new Department();
		department.setName(name);
		department.setEmployees(new ArrayList<Person>());

		return department;
	}

	public static Person createPerson(final String name, final Department department) {
		Assert.hasText(name);
		Assert.notNull(department);

		Person person = new Person();
		person.setName(name);
		person.setDepartment(department);
		department.getEmployees().add(person);

		return person;
	}

	public static Role createRole(final String description) {
		Assert.notNull(description);

		Role role = new Role();
		role.setDescription(description);
		role.setUsers(new ArrayList<User>());

		return role;
	}

	public static User createUser(final String username, final String password) {
		return createUser(null, username, password);
	}

	public static User createUser(final Person person, final String username, final String password) {
		Assert.hasText(username);
		Assert.notNull(password);

		User user = new User();
		user.setPerson(person);
		user.setUsername(username);
		user.setPassword(password);
		user.setRegistrationDate(new Date());
		user.setRoles(new ArrayList<Role>());

		return user;
	}

}
